package familytree.yu.com.admin.web.adminclient;

import familytree.yu.com.admin.api.entity.memberinfo.BaseMemberLoginInfoEntity;
import familytree.yu.com.admin.api.service.memberinfo.IBaseMemberLoginInfoService;
import familytree.yu.com.adminclient.api.MemberInfoClientApiService;
import familytree.yu.com.adminclient.entity.MemberEntity;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * @Author: yuyunbo
 * @Date: 2021/2/25 22:09
 * @Description:
 */
@DubboService
public class MemberInfoClientApiServiceImpl implements MemberInfoClientApiService {

    @Autowired
    private IBaseMemberLoginInfoService baseMemberLoginInfoService;


    /**
     * 根据用户名查询用户信息
     *
     * @param userName
     * @return
     */
    @Override
    public MemberEntity queryByUserName(String userName) {
        BaseMemberLoginInfoEntity baseMemberLoginInfoEntity = baseMemberLoginInfoService.querBaseMemberLoginInfo(userName);
        if (baseMemberLoginInfoEntity != null) {
            MemberEntity memberEntity = new MemberEntity();
            memberEntity.setMemberCode(baseMemberLoginInfoEntity.getMemberCode());
            memberEntity.setMemberPhone(baseMemberLoginInfoEntity.getMemberPhone());
            memberEntity.setMemberPassword(baseMemberLoginInfoEntity.getMemberPassword());
            return memberEntity;
        }
        return null;
    }

    /**
     * 保存会员登录信息
     *
     * @param memberEntity
     */
    @Override
    public void saveMemberInfo(MemberEntity memberEntity) {
        BaseMemberLoginInfoEntity baseMemberLoginInfoEntity = BaseMemberLoginInfoEntity.builder().memberCode("1q2w3e4r")
                .memberPhone(memberEntity.getMemberPhone()).memberPassword(memberEntity.getMemberPassword()).gmtCreated(new Date()).gmtCreatedBy("yuyunbo").build();
        baseMemberLoginInfoService.saveBaseMemberLoginInfo(baseMemberLoginInfoEntity);
    }

    /**
     * 更新会员信息
     *
     * @param memberEntity
     */
    @Override
    public void updateMemberInfo(MemberEntity memberEntity) {

    }
}
